#ifndef TABLE_H
#define TABLE_H

#include "pager.h"
#include "BPlusTree.h"
#include "record.h"

#define MAX_RECORDS_NUM 2000

typedef struct Table {
    int type;
    int record_count;
    pager_t *pager;
    BPlusTree tree;
} table_t;

typedef struct ReturnTable {
    char *colrefs[20];      /* column references */
    char **values;          /* return values */
    int colnum;             /* the number of column references */
    int valnum;             /* the number of values */
    int bufsz;              /* the size of values buf */
} rettbl_t;

table_t *createTable(int type);
void destroyTable(table_t *table);
int insert(table_t *table, record_t *record);
int delete(table_t *table, int index);
int search(table_t *table, int index, record_t *record);
int modify(table_t *table, int index, record_t *record);
int getRecord(table_t *table, int pos, record_t *record);
int flushPages(table_t *table, FILE *file);
int loadPages(table_t *table, FILE *file);

void initrettbl(rettbl_t *rettbl);
void destroyrettbl(rettbl_t *rettbl);
int addcolref(rettbl_t *rettbl, const char *col);
int addtblref(rettbl_t *rettbl, int type);
int addvalue(rettbl_t *rettbl, record_t *record);

#endif  /* TABLE_H */